import requests
import json
from upload_img import getUrl
import os.path as osp

localhost = "http://127.0.0.1:5700"

def getGroupList():
    return requests.get(localhost + '/get_group_list').json()

def getStrangerInfo(id):
    json_data = requests.get(localhost + '/get_stranger_info', params={'user_id':id}).json()
    return json_data['data']

def getGroupInfo(id):
    json_data = requests.get(localhost + '/get_group_info', params={'user_id':id}).json()
    return json_data['data']

def sendMsgToGroup(msg, id):
    return requests.post(localhost + '/send_msg', params = {'message_type' : 'group',
                                      'message':msg, 'group_id':id}).json()
    

def process_img(src):
    return f'[CQ:image,file={src}]'

def process_face(id):
    return f'[CQ:face,id={id}]'

def process_at(q_id, msg):
    return f'[CQ:at,qq={q_id}] {msg}'



def msg_sender(msg=None, id = None,  type = None):

    if msg == None:
        msg = input("输入消息:\n")

    if type == 'private':
        requests.get(localhost + '/send_msg', params = {'message_type' : type,
                                      'message':msg, 'user_id':id})
        
    else:
        requests.get(localhost + '/send_msg', params = {'message_type' : type,
                                      'message':msg, 'group_id':id})


def main():

    option = input("1.发送文本消息\n2.发送图片\n3.发送表情\n:")
    if(int(option) == 1):
        msg_sender(id=767694190, type='group')
    elif int(option) == 2:
        src = input("输入图片url:\n")
        url = None
        if src == " ":
            url = getUrl()
            msg_sender(process_img(url), id=767694190, type='group')
            return 'ok' 
        else:
            url = getUrl(src) if osp.exists(src) else src
            msg_sender(process_img(url), id=767694190, type='group')
         
    else:
        id = input("输入表情id:\n")
        msg_sender(process_face(id), id=767694190, type='group')


if __name__ == '__main__':
    while(True):
        main()


